package com.dianping.cat.alarm.server.transform;

import com.dianping.cat.alarm.server.entity.Condition;
import com.dianping.cat.alarm.server.entity.Rule;
import com.dianping.cat.alarm.server.entity.ServerAlarmRuleConfig;
import com.dianping.cat.alarm.server.entity.SubCondition;
import org.xml.sax.Attributes;










public class DefaultSaxMaker
  extends Object
  implements IMaker<Attributes>
{
  public Condition buildCondition(Attributes attributes) {
/*  23 */     String interval = attributes.getValue("interval");
    String duration = attributes.getValue("duration");
    String alertType = attributes.getValue("alert-type");
/*  26 */     Condition condition = new Condition();

/*  28 */     if (interval != null) {
      condition.setInterval(interval);
    }

    if (duration != null) {
/*  33 */       condition.setDuration(((Integer)convert(Integer.class, duration, Integer.valueOf(0))).intValue());
    }

    if (alertType != null) {
/*  37 */       condition.setAlertType(alertType);
    }

/*  40 */     return condition;
  }


  public Rule buildRule(Attributes attributes) {
/*  45 */     String startTime = attributes.getValue("start-time");
/*  46 */     String endTime = attributes.getValue("end-time");
/*  47 */     Rule rule = new Rule();

/*  49 */     if (startTime != null) {
/*  50 */       rule.setStartTime(startTime);
    }

/*  53 */     if (endTime != null) {
/*  54 */       rule.setEndTime(endTime);
    }

/*  57 */     return rule;
  }


  public ServerAlarmRuleConfig buildServerAlarmRuleConfig(Attributes attributes) {
/*  62 */     String id = attributes.getValue("id");
/*  63 */     ServerAlarmRuleConfig serverAlarmRuleConfig = new ServerAlarmRuleConfig();

/*  65 */     if (id != null) {
/*  66 */       serverAlarmRuleConfig.setId(id);
    }

/*  69 */     return serverAlarmRuleConfig;
  }


  public SubCondition buildSubCondition(Attributes attributes) {
/*  74 */     String type = attributes.getValue("type");
/*  75 */     String value = attributes.getValue("value");
/*  76 */     SubCondition subCondition = new SubCondition();

    if (type != null) {
/*  79 */       subCondition.setType(type);
    }

/*  82 */     if (value != null) {
/*  83 */       subCondition.setValue(value);
    }

/*  86 */     return subCondition;
  }


  protected <T> T convert(Class<T> type, String value, T defaultValue) {
/*  91 */     if (value == null || value.length() == 0) {
/*  92 */       return defaultValue;
    }

/*  95 */     if (type == Boolean.class || type == boolean.class)
/*  96 */       return (T)Boolean.valueOf(value); 
/*  97 */     if (type == Integer.class || type == int.class)
/*  98 */       return (T)Integer.valueOf(value); 
/*  99 */     if (type == Long.class || type == long.class)
/* 100 */       return (T)Long.valueOf(value); 
/* 101 */     if (type == Short.class || type == short.class)
/* 102 */       return (T)Short.valueOf(value); 
/* 103 */     if (type == Float.class || type == float.class)
/* 104 */       return (T)Float.valueOf(value); 
/* 105 */     if (type == Double.class || type == double.class)
/* 106 */       return (T)Double.valueOf(value); 
/* 107 */     if (type == Byte.class || type == byte.class)
/* 108 */       return (T)Byte.valueOf(value); 
/* 109 */     if (type == Character.class || type == char.class) {
/* 110 */       return (T)Character.valueOf(value.charAt(0));
    }
/* 112 */     return (T)value;
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-alarm-3.0.0.jar!/com/dianping/cat/alarm/server/transform/DefaultSaxMaker.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */